/*
 * Copyright (c) 2023, mr-library Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-04-23     MacRsh       first version
 */

#include "drv_uart.h"

#if defined(MR_CFG_SERIAL)

static struct mr_serial serial_device[1];

static mr_err_t sim_serial_configure(mr_serial_t serial, struct mr_serial_config *config)
{
    return MR_ERR_OK;
}

static void sim_serial_write(mr_serial_t serial, mr_uint8_t data)
{
    putchar((char)data);
    return;
}

static mr_uint8_t sim_serial_read(mr_serial_t serial)
{
    return 0;
}

static void sim_serial_start_tx(mr_serial_t serial)
{
    return;
}

static void sim_serial_stop_tx(mr_serial_t serial)
{
    return;
}

static void sim_serial_isr(mr_serial_t serial)
{
    return;
}

mr_err_t drv_uart_init(void)
{
    static struct mr_serial_ops drv_ops =
        {
            sim_serial_configure,
            sim_serial_write,
            sim_serial_read,
            sim_serial_start_tx,
            sim_serial_stop_tx,
        };

    mr_err_t ret = MR_ERR_OK;
    ret = mr_serial_device_add(&serial_device[0], MR_CFG_CONSOLE_NAME, &drv_ops, NULL);
    MR_ASSERT(ret == MR_ERR_OK);

    return ret;
}
MR_INIT_DRIVER_EXPORT(drv_uart_init);

#endif
